﻿Imports ajayumi.develop.VBasic.Core
Imports ajayumi.develop.VBasic.Core.Drawing

Public Class ImageForm
    Inherits ajayumi.develop.VBasic.Win.Controls.Forms.ImageForm
    Implements IComparable(Of ImageForm)


#Region "variables"
    Private m_RequireClose As Boolean = True
#End Region

#Region "properties"

    Private m_ProgramInfo As ProgramInfo = Nothing
    Public Property ProgramInfo() As ProgramInfo
        Get
            Return m_ProgramInfo
        End Get
        Set(ByVal value As ProgramInfo)
            m_ProgramInfo = value
        End Set
    End Property


#End Region

    Public Sub New(ByVal pgInfo As ProgramInfo)
        MyBase.New()
        Me.m_ProgramInfo = pgInfo
        Me.AllowDragMove = False
        Me.ShowTip = True
        Me.Tip = pgInfo.Name
        Me.TipHorizontalAlign = VBasic.Win.Controls.Forms.TipHorizontalAlign.Center
        Me.TipVerticalAlign = VBasic.Win.Controls.Forms.TipVerticalAlign.OuterBottom
        Me.m_FormImage = pgInfo.FormImage
    End Sub

    Protected Overrides Function InitFormImage() As System.Drawing.Image
        Dim _Image As Image = Nothing

        Using _ImageHelper As New ImageHelper()
            _Image = _ImageHelper.GetThumbnailImage(Me.m_FormImage, Me.m_ProgramInfo.FormImageSize.Width, Me.m_ProgramInfo.FormImageSize.Height)
        End Using

        Return _Image
    End Function

    Protected Overrides Sub DefaultStartPosition()
        Me.MoveToCenterScreen()
    End Sub

    Protected Overrides Sub OnMouseDoubleClick(ByVal e As System.Windows.Forms.MouseEventArgs)

    End Sub

    Protected Overrides Sub OnMouseClick(ByVal e As System.Windows.Forms.MouseEventArgs)
        MyBase.OnMouseClick(e)
        If e.Button = Windows.Forms.MouseButtons.Left Then
            If System.IO.File.Exists(Me.m_ProgramInfo.Path) = True Then
                Process.Start(Me.m_ProgramInfo.Path)
            Else
                MsgBox(String.Format("{0} 程序不存在", Me.m_ProgramInfo.Name), MsgBoxStyle.Critical)
            End If
        End If
    End Sub


    Public Function CompareTo(ByVal other As ImageForm) As Integer Implements System.IComparable(Of ImageForm).CompareTo
        Return Me.m_ProgramInfo.Order.CompareTo(other.m_ProgramInfo.Order)
    End Function

End Class
